package ch.unisi.inf.editor;

import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;


/**
 * this class is used to create a command for the filters
 * 
 * @author matthias.eberli@lu.unisi.ch
 */
public class FilterCommand extends AbstractAction
{

    private final ImagePanel imagePanel;
    private final Filter filter;
    
    public FilterCommand(final ImagePanel imagePanel, final Filter filter) {

        this.imagePanel = imagePanel;
        this.filter = filter;
        // menu item text
        putValue(NAME, filter.getName());
        putValue(SHORT_DESCRIPTION, "Apply filter" + filter.getName());
       // setEnabled(imagePanel.hasImage());
        
        imagePanel.addImagePanelListener(new ImagePanelListener() {
            public void imageCharged() {
                setEnabled(imagePanel.hasImage());
            }
        });
        
    }
    
    public void actionPerformed(final ActionEvent ev) 
    {
        imagePanel.applyFilter(filter);
    }
   
}
